package org.ants.basecomponent.service.user;

import org.ants.basecomponent.dao.user.SysUserDao;
import org.ants.basecomponent.entity.user.SysUser;
import org.ants.tinymvc.dao.BaseTinyDbDao;
import org.ants.tinymvc.service.BaseTinyDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tinygroup.tinydb.Bean;

@Service
public class SysUserService extends BaseTinyDbService<SysUser> {

	@Autowired
	private SysUserDao sysUserDao;
	
	@Override
	protected BaseTinyDbDao<SysUser> getEntityDao() {
		return sysUserDao;
	}
	
	public SysUser login(String userId,String password) throws Exception{
		Bean bean = new Bean();
		bean.set("loginName", userId);
		bean.set("password", password);
		Bean[] beans = this.getEntityDao().findBeans(bean);
		return (SysUser) new SysUser().fromBean(beans[0]);
	}
}
